Simple GUI
This tutorial is how to make a simple Graphical User Interface, or "GUI". Here we will make an interesting agent, allowing us to: *teach the vocabulary to all the creatures in the game *save the game without quitting *quit the game without saving This little tutorial will tell you how to use BUTTONS in compound agents. At first we need a set of sprites: here I set them like this in the .c16 : *sprite 0 : the main part of the sprite *sprite 1 : the 'teach' button *sprite 2 : the 'save' button *sprite 3 : the 'quit' button *we install the agent in the game inst new: comp 2 24 11111 "tutogui" 4 0 9900 attr 38 *attributes ... floatable 32 + mouseable 2 + mouse activeable 4 bhvr 0 *and here the hardest part of the install script begins! *but don't worry, it is still quite simple **we create the button 'teach all creatures in game' pat: butt 1 "tutogui" 1 4 1 1 0 [] 3000 0 *I explain what all these odd numbers mean: *1 - it is the number of the created part - the main part of the agent has part 0 *"tutogui" refers to the name of the sprite file used for the part *1 tells the game that the image used for the button is the image 1 *4 tells the game that there are only 4 images in the sprite file *1 the position in 'x', related to the part 0 *1 the position in 'y', related to the part 0 *0 the plane difference between the part 0 and the new part *[] - if you want an animation when you roll your mouse over the button, you can put it here *3000 - it is the number of the message sent by the button when pressed *0 it means that the button will be activated even if you click on a transparent pixel of the button sprite **we create the second button, the button 'save' pat: butt 2 "tutogui" 2 4 22 1 0 [] 3001 0 *and the third button pat: butt 3 "tutogui" 3 4 43 1 0 [] 3002 0 *as you've seen, the number of the message sent changes with each button - the message is a random number, but you have to remember it, and never use the same message number for 2 different parts of an agent. mvto cmrx cmry *cmrx and cmry are the 'x' and 'y' position of the middle of the screen - mvto means that the agent will move to the nearest safe position around the camera's central (x;y) coordinates endm * ! the install script is finished! *now we have to define what will happen when we will press the buttons. Do you remember the messages we have sent with the buttons? Now we will use them! *script for the 'teach' button : scrp 2 24 11111 3000 *the '3000' is there as the number of the called script - the message sent refers to a script number, and that's why you can't have the same message sent by 2 different buttons - or you can, but the buttons will execute the same piece of code. *this means that if you want 2 buttons to do the same action, you can send the same message *if you want them to have a different action, you MUST change the message and script number enum 4 0 0 vocb next *here we 'enum' all the agents matching the '4 0 0' classifiers - this means all creatures *'vocb' teaches the vocabulary to these creatures *'next' closes the enum command endm *script for the 'save' button scrp 2 24 11111 3001 save endm *script for the 'quit' button scrp 2 24 11111 3002 quit endm *the remove script rscr enum 2 24 11111 kill targ next Tutorial by zareb Category:TutorialsCategory:C3/DS CAOS